home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Menu / c / ReviseWdth < prev    next >
Text File  |  1995-07-22  |  2KB  |  64 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Menu.ReviseWdth.c
  12.     Author:  Copyright © 1994 Lenny
  13.     Version: 0.02 (20 Nov 1994)
  14.     Purpose: Revises a menu's width, according to the longest menu item.
  15.     History: 0.01 (20 Nov 94) : Added 'Menu_ReviseWidth()'
  16.     Mods:    22 Jul 1995 - JPS - Set maxwidth to 0 initially
  17.  
  18. */
  19.  
  20.  
  21. #include "DeskLib:Wimp.h"
  22. #include "DeskLib:Menu.h"
  23.  
  24. #include <string.h>
  25.  
  26.  
  27. extern void Menu_ReviseWidth(menu_ptr menu)
  28. /*
  29.  *  Revises a menu's width, by scanning through all the items.
  30.  *  The title width is also taken into consideration.
  31.  *  It is assumed that there is AT LEAST ONE item in the menu.
  32.  *
  33.  *  Use it after using Menu_SetText(), or when updating the
  34.  *  contents of an indirected text menu item, ie when having
  35.  *  used Menu_MakeIndirected().
  36.  */
  37. {
  38.   int                   width, maxwidth=0;
  39.   BOOL                  last = FALSE;
  40.   menu_item   *item = (menu_item *) (((int) menu) + sizeof(menu_block));
  41.  
  42.   do {
  43.     if (item->iconflags.data.indirected) {
  44.       width = strlen(item->icondata.indirecttext.buffer);
  45.     } 
  46.     else {
  47.       width = strlen(item->icondata.text);
  48.       if (width > 12)  width = 12;  /* It's a full length non-terminated entry */
  49.     }
  50.     if (width > maxwidth)  maxwidth = width;
  51.     if (item->menuflags.data.last)  last = TRUE;
  52.     item++;
  53.   } while (last == FALSE);
  54.   maxwidth += 1;
  55.  
  56.   width = strlen(menu->title);
  57.   if (width > 12)  width = 12;  /* It's a full length non-terminated title */
  58.   if (width > maxwidth)  maxwidth = width;
  59.  
  60.   menu->width = maxwidth * 16;
  61.  
  62. }
  63.  
  64.